﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Client
{
    public partial class FormAddUser : BasePopForm
    {
        QunYing.BLL.Employee bll_Emloyee = new QunYing.BLL.Employee();
        QunYing.BLL.UserLoginInfo bll_userLogin = new QunYing.BLL.UserLoginInfo();
        public FormAddUser()
        {
            InitializeComponent();
            this.FormValidator.SetControlValitors(this.txt_密码, Spore.Validator.ValidatorDefaults.NotNull);
            this.FormValidator.SetControlValitors(this.txt_用户名, Spore.Validator.ValidatorDefaults.NotNull);
        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txt_用户名.Text.Trim()))
                {
                    GlobalInfo.MsgBoxShowError("用户名不能为空");
                    return;
                }
                if (string.IsNullOrEmpty(this.txt_密码.Text.Trim()))
                {
                    GlobalInfo.MsgBoxShowError("密码不能为空");
                    return;
                }
                if (bll_Emloyee.Exists(this.txt_用户名.Text.Trim()))
                {
                    GlobalInfo.MsgBoxShowError("已存在该登录名！");
                    return;
                }
                if (bll_userLogin.Exists(this.txt_用户名.Text.Trim()))
                {
                    GlobalInfo.MsgBoxShowError("已存在该登录名！");
                    return;
                }
                QunYing.Model.Employee emp = new QunYing.Model.Employee();
                emp.所属经销商 = GlobalInfo.UserLoginInfo.用户ID;
                emp.是否启用 = this.ced_启动.Checked;
                emp.用户名 = this.txt_用户名.Text.Trim();
                emp.密码 = this.txt_密码.Text.Trim();
                emp.验证信息 = null;
                bll_Emloyee.Add(emp);
                this.DialogResult = DialogResult.Yes;
            }
            catch (Exception ex)
            {
                GlobalInfo.MsgBoxShowError("添加员工时发生错误："+ex.Message);
            }
        }

        private void btn_关闭_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}